package com.one.consumer.reserve.presenter;

import android.content.Context;

import com.one.common.model.http.callback.ObserverOnResultListener;
import com.one.common.presenter.BaseApiPresenter;
import com.one.common.utils.list.ArrayUtils;
import com.one.common.utils.list.ListUtils;
import com.one.common.view.base.BaseActivity;
import com.one.common.view.base.IListView;
import com.one.consumer.reserve.model.ReserveModel;
import com.one.consumer.reserve.model.extra.CaseExtra;
import com.one.consumer.reserve.model.item.CaseDetailItem;
import com.one.consumer.reserve.model.item.CaseItem;
import com.one.consumer.reserve.model.item.ProgramImageItem;

import java.util.ArrayList;

/**
 * author ：zhulunjun
 * email  ：zhulunjun@qq.com
 * date   ：2018/10/21 下午9:16
 * description ：
 **/
public class DECaseDetailPresenter extends BaseApiPresenter<IListView, ReserveModel> {
    private CaseExtra mExtra;

    public DECaseDetailPresenter(IListView mView, Context mContext) {
        super(mView, mContext, new ReserveModel((BaseActivity) mContext));
    }

    @Override
    public void onCreate() {
        super.onCreate();
        mExtra = (CaseExtra) mActivity.getIntent().getSerializableExtra(CaseExtra.getExtraName());
    }


    public CaseExtra getExtra() {
        return mExtra;
    }

    /**
     * 获取案例详情
     */
    public void getCaseDetail() {
        if (mExtra != null)
            mModel.getCaseDetailDE(mExtra.getCaseId(), objects -> {
                if (objects != null && mView != null) {
                    mView.loadSuccess(objects.getEffectImgBeans());
                }
            });
    }

    /**
     * 户型案例效果图
     */
    public void getProgramImg() {
        if (mExtra != null) {
//            String[] imgs = mExtra.getImags().split(",");
//            ArrayList<CaseDetailItem> datas = new ArrayList<>();
//            for (int i = 0; i < imgs.length; i++) {
//                CaseDetailItem item = new CaseDetailItem(imgs[i]);
//                datas.add(item);
//            }
//            mView.loadSuccess(datas);
            mModel.getProgramImags(mExtra.getProgramme_id(), programImageItems -> {
                if(mView!=null){
                    mView.loadSuccess(programImageItems);
                }
            });
        }
    }
}
